﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web_Oto.Business;
using Web_Oto.Common;
using Web_Oto.Data;

namespace Web_Oto.UC
{
    public partial class Footer : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
                GetSubCategory();
        }

        private void GetSubCategory()
        {
            var categoryBus = new CategoryBus();
            var subcategories = categoryBus.GetSubCategories();
            if (subcategories.Any())
            {
                var sb = new StringBuilder();
                foreach (var subcategory in subcategories)
                {
                    var parent = categoryBus.GetCategoryById(Convert.ToInt32(subcategory.ParentId));
                    sb.AppendFormat("<li rel='{1}'><a href='/san-pham/{0}/{1}/1.html'>{2}</a></li>",
                                CommonHelper.NiceUrl(parent.Name), CommonHelper.NiceUrl(subcategory.Name), subcategory.Name);
                }
                ltrSubCategory.Text = sb.ToString();
            }
        }
    }
}